<script setup lang="ts">
import { ref } from 'vue'
import { regInfoConst } from './regInfoConst'
import { onLoad, onUnload } from '@dcloudio/uni-app'
import { getRegistrationInfo } from '@/services/registration'
import type { GetRegInfoResult } from '@/types/registration'
import dayjs from 'dayjs'

const query = defineProps<{
  id: number
}>()

const { img, json } = regInfoConst()
const flag = ref(true)
const regInfo = ref<GetRegInfoResult>()
const qrcode = ref()
const prescriptionId = ref()

onLoad(async () => {
  await getRegistrationInfo({ id: query.id }).then((res) => {
    regInfo.value = res.result
    if (['主任医师', '副主任医师'].includes(regInfo.value.job)) {
      regInfo.value.type = '专家号'
    } else {
      regInfo.value.type = '普通号'
    }
    regInfo.value.dateTime = regInfo.value.date + ' ' + json[regInfo.value.slot]
    regInfo.value.amount = regInfo.value.amount + ' 元'
    // let today = dayjs().format('YYYY-MM-DD')
    // if (today == regInfo.value.date && regInfo.value.paymentStatus == 2) {
    //   flag.value = true
    // } else {
    //   flag.value = false
    // }
  })
})

onUnload(() => {
  let pages = getCurrentPages()
  let prevPage = pages[pages.length - 2]
  prevPage.$vm['reload'] = false
})
</script>

<template>
  <view v-if="regInfo">
    <view class="top-container" v-if="flag">
      <image :src="img.logo" mode="widthFix" class="logo"></image>
      <text class="title">北京市神州互联网医院</text>
      <view class="qrcode-container">
        <view class="qrcode">
          <view class="qrcode"
            ><uqrcode
              ref="qrcode"
              canvas-id="qrcode"
              size="140"
              :value="regInfo.outTradeNo"
            ></uqrcode
          ></view>
        </view>
        <text>就诊请出示二维码</text>
      </view>
      <view class="step-container">
        <view class="step">
          <view class="icon-1"></view>
          <text>在门诊台取号</text>
        </view>
        <view class="line"></view>
        <view class="step">
          <view class="icon-2"></view>
          <text>安静排队候诊</text>
        </view>
        <view class="line"></view>
        <view class="step">
          <view class="icon-3"></view>
          <text>就诊出示二维码</text>
        </view>
      </view>
    </view>
    <view class="registration-container">
      <view class="title"><text>挂号信息</text></view>
      <view class="registration">
        <u-cell-group :border="false">
          <u-cell title="就诊科室" :border="false" :value="regInfo.subDeptName"></u-cell>
          <u-cell title="就诊医生" :border="false" :value="regInfo.doctorName"></u-cell>
          <u-cell title="挂号类型" :border="false" :value="regInfo.type"></u-cell>
          <u-cell title="门诊位置" :border="false" :value="regInfo.location"></u-cell>
          <u-cell title="就诊时间" :border="false" :value="regInfo.dateTime"></u-cell>
          <u-cell title="挂号人" :border="false" :value="regInfo.patientName"></u-cell>
          <u-cell title="挂号费" :border="false" :value="regInfo.amount"></u-cell>
          <u-cell
            v-if="regInfo.prescriptionId != null"
            title="电子处方"
            :border="false"
            isLink
            :url="`/registration/prescription/prescription?registrationId=${regInfo.prescriptionId}`"
          ></u-cell>
        </u-cell-group>
      </view>
    </view>
  </view>
</template>

<style lang="less">
@import url('registration_info.less');
</style>
